
<!doctype html>
<html lang="zh" class="no-js">
  <head>
    
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width,initial-scale=1">
      
      
      
      
        <link rel="prev" href="../API_Reference/">
      
      
        <link rel="next" href="../../AT_Framwork_Guide/AT_Firmware_and_SAL_Firmware_User_Guide/">
      
      <link rel="icon" href="../../assets/favicon.png">
      <meta name="generator" content="mkdocs-1.4.3, mkdocs-material-9.1.19">
    
    
      
        <title>TobudOS内核CMSIS适配API指南 - TobudOS Documentation</title>
      
    
    
      <link rel="stylesheet" href="../../assets/stylesheets/main.eebd395e.min.css">
      
        
        <link rel="stylesheet" href="../../assets/stylesheets/palette.ecc896b0.min.css">
      
      

    
    
    
      
        
        
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
        <style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
      
    
    
    <script>__md_scope=new URL("../..",location),__md_hash=e=>[...e].reduce((e,_)=>(e<<5)-e+_.charCodeAt(0),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
    
      

    
    
    
  </head>
  
  
    
    
      
    
    
    
    
    <body dir="ltr" data-md-color-scheme="default" data-md-color-primary="indigo" data-md-color-accent="indigo">
  
    
    
      <script>var palette=__md_get("__palette");if(palette&&"object"==typeof palette.color)for(var key of Object.keys(palette.color))document.body.setAttribute("data-md-color-"+key,palette.color[key])</script>
    
    <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
    <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
    <label class="md-overlay" for="__drawer"></label>
    <div data-md-component="skip">
      
        
        <a href="#1-cmsis-rtos-api" class="md-skip">
          跳转至
        </a>
      
    </div>
    <div data-md-component="announce">
      
    </div>
    
    
      

<header class="md-header" data-md-component="header">
  <nav class="md-header__inner md-grid" aria-label="页眉">
    <a href="../.." title="TobudOS Documentation" class="md-header__button md-logo" aria-label="TobudOS Documentation" data-md-component="logo">
      
  <img src="../../assets/logo.png" alt="logo">

    </a>
    <label class="md-header__button md-icon" for="__drawer">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2Z"/></svg>
    </label>
    <div class="md-header__title" data-md-component="header-title">
      <div class="md-header__ellipsis">
        <div class="md-header__topic">
          <span class="md-ellipsis">
            TobudOS Documentation
          </span>
        </div>
        <div class="md-header__topic" data-md-component="header-topic">
          <span class="md-ellipsis">
            
              TobudOS内核CMSIS适配API指南
            
          </span>
        </div>
      </div>
    </div>
    
      
        <form class="md-header__option" data-md-component="palette">
          
            
            
            
            <input class="md-option" data-md-color-media="" data-md-color-scheme="default" data-md-color-primary="indigo" data-md-color-accent="indigo"  aria-label="Switch to dark mode"  type="radio" name="__palette" id="__palette_1">
            
              <label class="md-header__button md-icon" title="Switch to dark mode" for="__palette_2" hidden>
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a4 4 0 0 0-4 4 4 4 0 0 0 4 4 4 4 0 0 0 4-4 4 4 0 0 0-4-4m0 10a6 6 0 0 1-6-6 6 6 0 0 1 6-6 6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12 20 8.69Z"/></svg>
              </label>
            
          
            
            
            
            <input class="md-option" data-md-color-media="" data-md-color-scheme="slate" data-md-color-primary="indigo" data-md-color-accent="indigo"  aria-label="Switch to light mode"  type="radio" name="__palette" id="__palette_2">
            
              <label class="md-header__button md-icon" title="Switch to light mode" for="__palette_1" hidden>
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 18c-.89 0-1.74-.2-2.5-.55C11.56 16.5 13 14.42 13 12c0-2.42-1.44-4.5-3.5-5.45C10.26 6.2 11.11 6 12 6a6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12 20 8.69Z"/></svg>
              </label>
            
          
        </form>
      
    
    
      <div class="md-header__option">
        <div class="md-select">
          
          <button class="md-header__button md-icon" aria-label="选择当前语言">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="m12.87 15.07-2.54-2.51.03-.03A17.52 17.52 0 0 0 14.07 6H17V4h-7V2H8v2H1v2h11.17C11.5 7.92 10.44 9.75 9 11.35 8.07 10.32 7.3 9.19 6.69 8h-2c.73 1.63 1.73 3.17 2.98 4.56l-5.09 5.02L4 19l5-5 3.11 3.11.76-2.04M18.5 10h-2L12 22h2l1.12-3h4.75L21 22h2l-4.5-12m-2.62 7 1.62-4.33L19.12 17h-3.24Z"/></svg>
          </button>
          <div class="md-select__inner">
            <ul class="md-select__list">
              
                <li class="md-select__item">
                  <a href="./" hreflang="zh" class="md-select__link">
                    中文
                  </a>
                </li>
              
                <li class="md-select__item">
                  <a href="../../en/DevelopGuide/CMSIS_RTOS_API_Use_Guide/" hreflang="en" class="md-select__link">
                    English
                  </a>
                </li>
              
            </ul>
          </div>
        </div>
      </div>
    
    
      <label class="md-header__button md-icon" for="__search">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
      </label>
      <div class="md-search" data-md-component="search" role="dialog">
  <label class="md-search__overlay" for="__search"></label>
  <div class="md-search__inner" role="search">
    <form class="md-search__form" name="search">
      <input type="text" class="md-search__input" name="query" aria-label="搜索" placeholder="搜索" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
      <label class="md-search__icon md-icon" for="__search">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
      </label>
      <nav class="md-search__options" aria-label="查找">
        
          <a href="javascript:void(0)" class="md-search__icon md-icon" title="分享" aria-label="分享" data-clipboard data-clipboard-text="" data-md-component="search-share" tabindex="-1">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M18 16.08c-.76 0-1.44.3-1.96.77L8.91 12.7c.05-.23.09-.46.09-.7 0-.24-.04-.47-.09-.7l7.05-4.11c.54.5 1.25.81 2.04.81a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3c0 .24.04.47.09.7L8.04 9.81C7.5 9.31 6.79 9 6 9a3 3 0 0 0-3 3 3 3 0 0 0 3 3c.79 0 1.5-.31 2.04-.81l7.12 4.15c-.05.21-.08.43-.08.66 0 1.61 1.31 2.91 2.92 2.91 1.61 0 2.92-1.3 2.92-2.91A2.92 2.92 0 0 0 18 16.08Z"/></svg>
          </a>
        
        <button type="reset" class="md-search__icon md-icon" title="清空当前内容" aria-label="清空当前内容" tabindex="-1">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41Z"/></svg>
        </button>
      </nav>
      
        <div class="md-search__suggest" data-md-component="search-suggest"></div>
      
    </form>
    <div class="md-search__output">
      <div class="md-search__scrollwrap" data-md-scrollfix>
        <div class="md-search-result" data-md-component="search-result">
          <div class="md-search-result__meta">
            正在初始化搜索引擎
          </div>
          <ol class="md-search-result__list" role="presentation"></ol>
        </div>
      </div>
    </div>
  </div>
</div>
    
    
      <div class="md-header__source">
        <a href="https://atomgit.com/tobudos/Document" title="前往仓库" class="md-source" data-md-component="source">
  <div class="md-source__icon md-icon">
    
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 496 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc.--><path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"/></svg>
  </div>
  <div class="md-source__repository">
    Atomgit
  </div>
</a>
      </div>
    
  </nav>
  
</header>
    
    <div class="md-container" data-md-component="container">
      
      
        
          
            
<nav class="md-tabs" aria-label="标签" data-md-component="tabs">
  <div class="md-grid">
    <ul class="md-tabs__list">
      
        
  
  


  <li class="md-tabs__item">
    <a href="../.." class="md-tabs__link">
      首页
    </a>
  </li>

      
        
  
  


  <li class="md-tabs__item">
    <a href="../../Introduction/TobudOS_Brief_Introduction/" class="md-tabs__link">
      项目特性简介
    </a>
  </li>

      
        
  
  


  
  
  
    <li class="md-tabs__item">
      <a href="../../Kernel_Porting/Porting_Manual_for_KEIL/" class="md-tabs__link">
        内核移植指南
      </a>
    </li>
  

      
        
  
  
    
  


  
  
  
    <li class="md-tabs__item">
      <a href="../Development_Manual/" class="md-tabs__link md-tabs__link--active">
        内核开发指南
      </a>
    </li>
  

      
        
  
  


  
  
  
    <li class="md-tabs__item">
      <a href="../../AT_Framwork_Guide/AT_Firmware_and_SAL_Firmware_User_Guide/" class="md-tabs__link">
        AT模组框架
      </a>
    </li>
  

      
        
  
  


  <li class="md-tabs__item">
    <a href="../../ElfLoader_Guide/ElfLoader_Quick_Start/" class="md-tabs__link">
      ElfLoader动态加载
    </a>
  </li>

      
        
  
  


  
  
  
    <li class="md-tabs__item">
      <a href="../../OTA_Guide/OTA_Quick_Start_based_EVB_MX_Plus/" class="md-tabs__link">
        固件升级
      </a>
    </li>
  

      
        
  
  


  <li class="md-tabs__item">
    <a href="../../MicroPython_Guide/BearPi_MicroPython_QuickStart/" class="md-tabs__link">
      MicroPython开发指南
    </a>
  </li>

      
        
  
  


  <li class="md-tabs__item">
    <a href="../../VFS_Guide/vfs/" class="md-tabs__link">
      文件系统
    </a>
  </li>

      
        
  
  


  <li class="md-tabs__item">
    <a href="../../GUI_Guide/gui/" class="md-tabs__link">
      GUI开发
    </a>
  </li>

      
        
  
  


  
  
  
    <li class="md-tabs__item">
      <a href="../../DevelopKit/1.EVB_MX_Plus_Quick_Start/" class="md-tabs__link">
        官方开发套件
      </a>
    </li>
  

      
    </ul>
  </div>
</nav>
          
        
      
      <main class="md-main" data-md-component="main">
        <div class="md-main__inner md-grid">
          
            
              
              <div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    

  


<nav class="md-nav md-nav--primary md-nav--lifted" aria-label="导航栏" data-md-level="0">
  <label class="md-nav__title" for="__drawer">
    <a href="../.." title="TobudOS Documentation" class="md-nav__button md-logo" aria-label="TobudOS Documentation" data-md-component="logo">
      
  <img src="../../assets/logo.png" alt="logo">

    </a>
    TobudOS Documentation
  </label>
  
    <div class="md-nav__source">
      <a href="https://atomgit.com/tobudos/Document" title="前往仓库" class="md-source" data-md-component="source">
  <div class="md-source__icon md-icon">
    
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 496 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc.--><path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"/></svg>
  </div>
  <div class="md-source__repository">
    Atomgit
  </div>
</a>
    </div>
  
  <ul class="md-nav__list" data-md-scrollfix>
    
      
      
      

  
  
  
    <li class="md-nav__item">
      <a href="../.." class="md-nav__link">
        首页
      </a>
    </li>
  

    
      
      
      

  
  
  
    <li class="md-nav__item">
      <a href="../../Introduction/TobudOS_Brief_Introduction/" class="md-nav__link">
        项目特性简介
      </a>
    </li>
  

    
      
      
      

  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3" >
      
      
        
          
        
          
        
          
        
      
      
        <label class="md-nav__link" for="__nav_3" id="__nav_3_label" tabindex="0">
          内核移植指南
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_3_label" aria-expanded="false">
        <label class="md-nav__title" for="__nav_3">
          <span class="md-nav__icon md-icon"></span>
          内核移植指南
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../Kernel_Porting/Porting_Manual_for_KEIL/" class="md-nav__link">
        基于Keil移植TobudOS内核
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../Kernel_Porting/Porting_Manual_for_IAR/" class="md-nav__link">
        基于IAR 移植TobudOS内核
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../Kernel_Porting/Porting_Manual_for_GCC/" class="md-nav__link">
        基于GCC 移植TobudOS内核
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
      
      
      

  
  
    
  
  
    
    <li class="md-nav__item md-nav__item--active md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_4" checked>
      
      
        
          
        
          
        
          
        
      
      
        <label class="md-nav__link" for="__nav_4" id="__nav_4_label" tabindex="0">
          内核开发指南
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_4_label" aria-expanded="true">
        <label class="md-nav__title" for="__nav_4">
          <span class="md-nav__icon md-icon"></span>
          内核开发指南
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../Development_Manual/" class="md-nav__link">
        TobudOS内核开发指南
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../API_Reference/" class="md-nav__link">
        TobudOS内核API参考手册
      </a>
    </li>
  

            
          
            
              
  
  
    
  
  
    <li class="md-nav__item md-nav__item--active">
      
      <input class="md-nav__toggle md-toggle" type="checkbox" id="__toc">
      
      
        
      
      
      <a href="./" class="md-nav__link md-nav__link--active">
        TobudOS内核CMSIS适配API指南
      </a>
      
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
      
      
      

  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5" >
      
      
        
          
        
          
        
      
      
        <label class="md-nav__link" for="__nav_5" id="__nav_5_label" tabindex="0">
          AT模组框架
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_5_label" aria-expanded="false">
        <label class="md-nav__title" for="__nav_5">
          <span class="md-nav__icon md-icon"></span>
          AT模组框架
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../AT_Framwork_Guide/AT_Firmware_and_SAL_Firmware_User_Guide/" class="md-nav__link">
        无线通信模组AT框架开发指南
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../AT_Framwork_Guide/How_To_Use_Esp8266_Tencent_Firmware_Connect_Iot_Explorer/" class="md-nav__link">
        基于AT框架和定制模组如何对接腾讯云IoT Explorer平台
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
      
      
      

  
  
  
    <li class="md-nav__item">
      <a href="../../ElfLoader_Guide/ElfLoader_Quick_Start/" class="md-nav__link">
        ElfLoader动态加载
      </a>
    </li>
  

    
      
      
      

  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_7" >
      
      
        
          
        
          
        
      
      
        <label class="md-nav__link" for="__nav_7" id="__nav_7_label" tabindex="0">
          固件升级
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_7_label" aria-expanded="false">
        <label class="md-nav__title" for="__nav_7">
          <span class="md-nav__icon md-icon"></span>
          固件升级
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../OTA_Guide/OTA_Quick_Start_based_EVB_MX_Plus/" class="md-nav__link">
        基于EVB_MX的固件升级指南
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../OTA_Guide/In_Application_Programming_based_EVB_MX_Plus/" class="md-nav__link">
        基于EVB_MX的IAP开发指南
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
      
      
      

  
  
  
    <li class="md-nav__item">
      <a href="../../MicroPython_Guide/BearPi_MicroPython_QuickStart/" class="md-nav__link">
        MicroPython开发指南
      </a>
    </li>
  

    
      
      
      

  
  
  
    <li class="md-nav__item">
      <a href="../../VFS_Guide/vfs/" class="md-nav__link">
        文件系统
      </a>
    </li>
  

    
      
      
      

  
  
  
    <li class="md-nav__item">
      <a href="../../GUI_Guide/gui/" class="md-nav__link">
        GUI开发
      </a>
    </li>
  

    
      
      
      

  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_11" >
      
      
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
      
      
        <label class="md-nav__link" for="__nav_11" id="__nav_11_label" tabindex="0">
          官方开发套件
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_11_label" aria-expanded="false">
        <label class="md-nav__title" for="__nav_11">
          <span class="md-nav__icon md-icon"></span>
          官方开发套件
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../DevelopKit/1.EVB_MX_Plus_Quick_Start/" class="md-nav__link">
        EVB_MX+（STM32L4）快速上手
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../DevelopKit/2.EVB_LX_RISC-V_Quick_Start/" class="md-nav__link">
        EVB_LX（GD32V RISC-V）快速上手
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../DevelopKit/3.EVB_WL_Quick_Start/" class="md-nav__link">
        EVB_WL（STM32WL）快速上手
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../DevelopKit/4.EVB_G0_QuickStart/" class="md-nav__link">
        EVB_G0（STM32G0）快速上手
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../DevelopKit/5.EVB_AIoT_NXP_QuickStart/" class="md-nav__link">
        EVB_AIoT_NXP（RT1062）快速上手
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../DevelopKit/6.EVB_CH32V_QuickStart/" class="md-nav__link">
        EVB_CH32V（CH32V307）快速上手
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../DevelopKit/7.EVB_AIoT_STM32_QuickStart/" class="md-nav__link">
        EVB_AIoT_STM32（STM32H7）快速上手
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
  </ul>
</nav>
                  </div>
                </div>
              </div>
            
            
              
              <div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    

<nav class="md-nav md-nav--secondary" aria-label="目录">
  
  
  
    
  
  
</nav>
                  </div>
                </div>
              </div>
            
          
          
            <div class="md-content" data-md-component="content">
              <article class="md-content__inner md-typeset">
                
                  

  
    <a href="https://atomgit.com/tobudos/Document/edit/master/docs/DevelopGuide/CMSIS_RTOS_API_Use_Guide.md" title="编辑此页" class="md-content__button md-icon">
      
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20.71 7.04c.39-.39.39-1.04 0-1.41l-2.34-2.34c-.37-.39-1.02-.39-1.41 0l-1.84 1.83 3.75 3.75M3 17.25V21h3.75L17.81 9.93l-3.75-3.75L3 17.25Z"/></svg>
    </a>
  
  
    
      
    
    <a href="https://atomgit.com/tobudos/Document/raw/master/docs/DevelopGuide/CMSIS_RTOS_API_Use_Guide.md" title="查看本页的源代码" class="md-content__button md-icon">
      
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 9a3 3 0 0 0-3 3 3 3 0 0 0 3 3 3 3 0 0 0 3-3 3 3 0 0 0-3-3m0 8a5 5 0 0 1-5-5 5 5 0 0 1 5-5 5 5 0 0 1 5 5 5 5 0 0 1-5 5m0-12.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5Z"/></svg>
    </a>
  


<h1 id="1-cmsis-rtos-api">1. CMSIS-RTOS API 是什么</h1>
<p>CMSIS-RTOS 是用于实时操作系统（RTOS）的一层通用 API，它提供了一套标准的 API 接口，可以移植到各种各样的 RTOS 上，使得上层的软件、中间件、库以及其他组件在不同的 RTOS 之上都可以正常工作。</p>
<p>这套 API 表现为两个文件：cmsis-os.h 和 cmsis-os.c，在 TobudOS 中如下。</p>
<ul>
<li>基于 TobudOS 的 CMSIS-RTOS API v1.02 版本实现：</li>
<li><code>cmsis_os.h</code></li>
<li><code>cmsis_os.c</code></li>
<li>基于 TobudOS 的 CMSIS-RTOS API v2.1.3 版本实现：</li>
<li><code>cmsis_os2.h</code></li>
<li><code>cmsis_os2.c</code></li>
</ul>
<p>CMSIS-RTOS API 的整体架构如下图：
<img alt="" src="../assets/cmsis-rtos-api.png" />
CMSIS-RTOS API 官方参考文档链接：<a href="https://www.keil.com/pack/doc/CMSIS/RTOS/html/index.html">https://www.keil.com/pack/doc/CMSIS/RTOS/html/index.html</a></p>
<h1 id="2-cmsis-rtos-api">2. CMSIS-RTOS API 列表</h1>
<p>下面列出了 CMSIS-RTOS API <font color="red">v1.02</font> 版本提供的所有 API。</p>
<p>CMSIS-RTOS 所有 API 使用的错误码（cmsis-os.h）：</p>
<div class="highlight"><pre><span></span><code><span class="k">typedef</span><span class="w"> </span><span class="k">enum</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="n">osOK</span><span class="w">                    </span><span class="o">=</span><span class="w">     </span><span class="mi">0</span><span class="p">,</span><span class="w">       </span><span class="c1">///&lt; function completed; no error or event occurred.</span>
<span class="w">    </span><span class="n">osEventSignal</span><span class="w">           </span><span class="o">=</span><span class="w">  </span><span class="mh">0x08</span><span class="p">,</span><span class="w">       </span><span class="c1">///&lt; function completed; signal event occurred.</span>
<span class="w">    </span><span class="n">osEventMessage</span><span class="w">          </span><span class="o">=</span><span class="w">  </span><span class="mh">0x10</span><span class="p">,</span><span class="w">       </span><span class="c1">///&lt; function completed; message event occurred.</span>
<span class="w">    </span><span class="n">osEventMail</span><span class="w">             </span><span class="o">=</span><span class="w">  </span><span class="mh">0x20</span><span class="p">,</span><span class="w">       </span><span class="c1">///&lt; function completed; mail event occurred.</span>
<span class="w">    </span><span class="n">osEventTimeout</span><span class="w">          </span><span class="o">=</span><span class="w">  </span><span class="mh">0x40</span><span class="p">,</span><span class="w">       </span><span class="c1">///&lt; function completed; timeout occurred.</span>
<span class="w">    </span><span class="n">osErrorParameter</span><span class="w">        </span><span class="o">=</span><span class="w">  </span><span class="mh">0x80</span><span class="p">,</span><span class="w">       </span><span class="c1">///&lt; parameter error: a mandatory parameter was missing or specified an incorrect object.</span>
<span class="w">    </span><span class="n">osErrorResource</span><span class="w">         </span><span class="o">=</span><span class="w">  </span><span class="mh">0x81</span><span class="p">,</span><span class="w">       </span><span class="c1">///&lt; resource not available: a specified resource was not available.</span>
<span class="w">    </span><span class="n">osErrorTimeoutResource</span><span class="w">  </span><span class="o">=</span><span class="w">  </span><span class="mh">0xC1</span><span class="p">,</span><span class="w">       </span><span class="c1">///&lt; resource not available within given time: a specified resource was not available within the timeout period.</span>
<span class="w">    </span><span class="n">osErrorISR</span><span class="w">              </span><span class="o">=</span><span class="w">  </span><span class="mh">0x82</span><span class="p">,</span><span class="w">       </span><span class="c1">///&lt; not allowed in ISR context: the function cannot be called from interrupt service routines.</span>
<span class="w">    </span><span class="n">osErrorISRRecursive</span><span class="w">     </span><span class="o">=</span><span class="w">  </span><span class="mh">0x83</span><span class="p">,</span><span class="w">       </span><span class="c1">///&lt; function called multiple times from ISR with same object.</span>
<span class="w">    </span><span class="n">osErrorPriority</span><span class="w">         </span><span class="o">=</span><span class="w">  </span><span class="mh">0x84</span><span class="p">,</span><span class="w">       </span><span class="c1">///&lt; system cannot determine priority or thread has illegal priority.</span>
<span class="w">    </span><span class="n">osErrorNoMemory</span><span class="w">         </span><span class="o">=</span><span class="w">  </span><span class="mh">0x85</span><span class="p">,</span><span class="w">       </span><span class="c1">///&lt; system is out of memory: it was impossible to allocate or reserve memory for the operation.</span>
<span class="w">    </span><span class="n">osErrorValue</span><span class="w">            </span><span class="o">=</span><span class="w">  </span><span class="mh">0x86</span><span class="p">,</span><span class="w">       </span><span class="c1">///&lt; value of a parameter is out of range.</span>
<span class="w">    </span><span class="n">osErrorOS</span><span class="w">               </span><span class="o">=</span><span class="w">  </span><span class="mh">0xFF</span><span class="p">,</span><span class="w">       </span><span class="c1">///&lt; unspecified RTOS error: run-time error but no other error message fits.</span>
<span class="w">    </span><span class="n">os_status_reserved</span><span class="w">      </span><span class="o">=</span><span class="w">  </span><span class="mh">0x7FFFFFFF</span><span class="w">  </span><span class="c1">///&lt; prevent from enum down-size compiler optimization.</span>
<span class="p">}</span><span class="w"> </span><span class="n">osStatus</span><span class="p">;</span>
</code></pre></div>
<p>CMSIS-RTOS API 一些可选项控制是否开启（cmsis-os.h）：</p>
<div class="highlight"><pre><span></span><code><span class="cp">#define osFeature_MainThread   1       </span><span class="c1">///&lt; main thread      1=main can be thread, 0=not available</span>
<span class="cp">#define osFeature_Pool         1       </span><span class="c1">///&lt; Memory Pools:    1=available, 0=not available</span>
<span class="cp">#define osFeature_MailQ        1       </span><span class="c1">///&lt; Mail Queues:     1=available, 0=not available</span>
<span class="cp">#define osFeature_MessageQ     1       </span><span class="c1">///&lt; Message Queues:  1=available, 0=not available</span>
<span class="cp">#define osFeature_Signals      0       </span><span class="c1">///&lt; maximum number of Signal Flags available per thread</span>
<span class="cp">#define osFeature_Semaphore    30       </span><span class="c1">///&lt; maximum count for \ref osSemaphoreCreate function</span>
<span class="cp">#define osFeature_Wait         0       </span><span class="c1">///&lt; osWait function: 1=available, 0=not available</span>
<span class="cp">#define osFeature_SysTick      1       </span><span class="c1">///&lt; osKernelSysTick functions: 1=available, 0=not available</span>
</code></pre></div>
<h2 id="21-kernel-information-and-control">2.1. 内核信息和控制（Kernel information and control）</h2>
<table>
<thead>
<tr>
<th align="center">API</th>
<th align="center">描述</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">osKernelInitialize</td>
<td align="center">初始化 RTOS 内核</td>
</tr>
<tr>
<td align="center">osKernelStart</td>
<td align="center">启动 RTOS 内核</td>
</tr>
<tr>
<td align="center">osKernelRunning</td>
<td align="center">Query if the RTOS kernel is running</td>
</tr>
<tr>
<td align="center">osKernelSysTick (可选)</td>
<td align="center">Get RTOS kernel system timer counter</td>
</tr>
<tr>
<td align="center">osKernelSysTickFrequency (可选)</td>
<td align="center">RTOS kernel system timer frequency in Hz</td>
</tr>
<tr>
<td align="center">osKernelSysTickMicroSec (可选)</td>
<td align="center">Convert microseconds value to RTOS kernel system timer value</td>
</tr>
</tbody>
</table>
<ul>
<li><code>osKernelInitialize</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osKernelInitialize</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
</code></pre></div>
<p>返回值：status code</p>
<ul>
<li><code>osKernelStart</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osKernelStart</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
</code></pre></div>
<p>返回值：status code</p>
<ul>
<li><code>osKernelRunning</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="kt">int32_t</span><span class="w"> </span><span class="nf">osKernelRunning</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
</code></pre></div>
<p>返回值：0 表示 RTOS 未启动，1 表示 RTOS 已经启动</p>
<ul>
<li><code>osKernelSysTick</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="kt">uint32_t</span><span class="w"> </span><span class="nf">osKernelSysTick</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
</code></pre></div>
<p>返回值：RTOS 内核系统当前的时间</p>
<h2 id="22-thread-management">2.2. 线程管理（Thread management）</h2>
<blockquote>
<p><code>##</code>连接符的作用是连接两个字符串，合为一个字符串。</p>
</blockquote>
<p>CMSIS-RTOS API 存放线程参数管理的结构体如下：</p>
<div class="highlight"><pre><span></span><code><span class="k">typedef</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">os_thread_def</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="kt">char</span><span class="w">           </span><span class="o">*</span><span class="n">name</span><span class="p">;</span><span class="w">       </span><span class="c1">///&lt; Thread name</span>
<span class="w">    </span><span class="n">os_pthread</span><span class="w">      </span><span class="n">pthread</span><span class="p">;</span><span class="w">    </span><span class="c1">///&lt; start address of thread function</span>
<span class="w">    </span><span class="n">osPriority</span><span class="w">      </span><span class="n">tpriority</span><span class="p">;</span><span class="w">  </span><span class="c1">///&lt; initial thread priority</span>
<span class="w">    </span><span class="kt">uint32_t</span><span class="w">        </span><span class="n">instances</span><span class="p">;</span><span class="w">  </span><span class="c1">///&lt; maximum number of instances of that thread function</span>
<span class="w">    </span><span class="n">k_stack_t</span><span class="w">      </span><span class="o">*</span><span class="n">stackbase</span><span class="p">;</span><span class="w">  </span><span class="c1">///&lt; base address of task</span>
<span class="w">    </span><span class="kt">uint32_t</span><span class="w">        </span><span class="n">stacksize</span><span class="p">;</span><span class="w">  </span><span class="c1">///&lt; stack size requirements in bytes; 0 is default stack size</span>
<span class="w">    </span><span class="n">k_timeslice_t</span><span class="w">   </span><span class="n">timeslice</span><span class="p">;</span><span class="w">  </span><span class="c1">///&lt; timeslice</span>
<span class="w">    </span><span class="n">k_task_t</span><span class="w">       </span><span class="o">*</span><span class="n">task</span><span class="p">;</span>
<span class="p">}</span><span class="w"> </span><span class="n">osThreadDef_t</span><span class="p">;</span>
</code></pre></div>
<p>CMSIS-RTOS API 定义线程的宏如下：</p>
<div class="highlight"><pre><span></span><code><span class="cp">#define osThreadDef(name, priority, instances, stacksz)  \</span>
<span class="cp">    k_task_t task_handler_##name; \</span>
<span class="cp">    k_stack_t task_stack_##name[(stacksz)]; \</span>
<span class="cp">    const osThreadDef_t os_thread_def_##name = \</span>
<span class="cp">        { #name, (os_pthread)(name), (osPriority)(priority), (instances), \</span>
<span class="cp">        (&amp;((task_stack_##name)[0])), (stacksz), ((k_timeslice_t)0u), (&amp;(task_handler_##name)) }</span>
</code></pre></div>
<blockquote>
<p>宏定义中的 instances 表示基于此任务参数，创建出几个任务实例，比如 instances 为 2，则会创建出两个任务。</p>
</blockquote>
<p>CMSIS-RTOS API 定义的获取线程参数结构体的宏如下：</p>
<div class="highlight"><pre><span></span><code><span class="cp">#define osThread(name)  \</span>
<span class="cp">    &amp;os_thread_def_##name</span>
</code></pre></div>
<p>管理线程参数的 API 如下：</p>
<table>
<thead>
<tr>
<th align="center">API</th>
<th align="center">描述</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">osThreadCreate</td>
<td align="center">创建线程并开始执行</td>
</tr>
<tr>
<td align="center">osThreadTerminate</td>
<td align="center">停止线程执行</td>
</tr>
<tr>
<td align="center">osThreadYield</td>
<td align="center">线程主动让出</td>
</tr>
<tr>
<td align="center">osThreadGetID</td>
<td align="center">获取当前正在运行线程的 ID</td>
</tr>
<tr>
<td align="center">osThreadSetPriority</td>
<td align="center">改变线程优先级</td>
</tr>
<tr>
<td align="center">osThreadGetPriority</td>
<td align="center">获取线程优先级</td>
</tr>
</tbody>
</table>
<ul>
<li><code>osThreadCreate</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="n">osThreadId</span><span class="w"> </span><span class="nf">osThreadCreate</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="n">osThreadDef_t</span><span class="w"> </span><span class="o">*</span><span class="n">thread_def</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">argument</span><span class="p">);</span>
</code></pre></div>
<p>其中 osThreadId 被定义为 k_task_t 指针类型：</p>
<div class="highlight"><pre><span></span><code><span class="k">typedef</span><span class="w"> </span><span class="n">k_task_t</span><span class="w"> </span><span class="o">*</span><span class="n">osThreadId</span><span class="p">;</span>
</code></pre></div>
<p>返回值：TobudOS 中的任务控制块类型指针。</p>
<ul>
<li><code>osThreadTerminate</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osThreadTerminate</span><span class="p">(</span><span class="n">osThreadId</span><span class="w"> </span><span class="n">thread_id</span><span class="p">);</span>
</code></pre></div>
<p>返回值：osStatus</p>
<ul>
<li><code>osThreadYield</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osThreadYield</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
</code></pre></div>
<p>返回值：osStatus</p>
<ul>
<li><code>osThreadGetID</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="n">osThreadId</span><span class="w"> </span><span class="nf">osThreadGetId</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><code>osThreadSetPriority</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osThreadSetPriority</span><span class="p">(</span><span class="n">osThreadId</span><span class="w"> </span><span class="n">thread_id</span><span class="p">,</span><span class="w"> </span><span class="n">osPriority</span><span class="w"> </span><span class="n">priority</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><code>osThreadGetPriority</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="n">osPriority</span><span class="w"> </span><span class="nf">osThreadGetPriority</span><span class="p">(</span><span class="n">osThreadId</span><span class="w"> </span><span class="n">thread_id</span><span class="p">);</span>
</code></pre></div>
<blockquote>
<p>使用时需要特别注意，在 TobudOS 中，调用 CMSIS-RTOS API 提供的优先级选项设置之后，实际设置的任务值是不同的。</p>
</blockquote>
<p>CMSIS-RTOS API 提供的线程优先级宏定义如下：</p>
<div class="highlight"><pre><span></span><code><span class="k">typedef</span><span class="w"> </span><span class="k">enum</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="n">osPriorityIdle</span><span class="w">          </span><span class="o">=</span><span class="w"> </span><span class="mi">-3</span><span class="p">,</span><span class="w">          </span><span class="c1">///&lt; priority: idle (lowest)</span>
<span class="w">    </span><span class="n">osPriorityLow</span><span class="w">           </span><span class="o">=</span><span class="w"> </span><span class="mi">-2</span><span class="p">,</span><span class="w">          </span><span class="c1">///&lt; priority: low</span>
<span class="w">    </span><span class="n">osPriorityBelowNormal</span><span class="w">   </span><span class="o">=</span><span class="w"> </span><span class="mi">-1</span><span class="p">,</span><span class="w">          </span><span class="c1">///&lt; priority: below normal</span>
<span class="w">    </span><span class="n">osPriorityNormal</span><span class="w">        </span><span class="o">=</span><span class="w">  </span><span class="mi">0</span><span class="p">,</span><span class="w">          </span><span class="c1">///&lt; priority: normal (default)</span>
<span class="w">    </span><span class="n">osPriorityAboveNormal</span><span class="w">   </span><span class="o">=</span><span class="w"> </span><span class="o">+</span><span class="mi">1</span><span class="p">,</span><span class="w">          </span><span class="c1">///&lt; priority: above normal</span>
<span class="w">    </span><span class="n">osPriorityHigh</span><span class="w">          </span><span class="o">=</span><span class="w"> </span><span class="o">+</span><span class="mi">2</span><span class="p">,</span><span class="w">          </span><span class="c1">///&lt; priority: high</span>
<span class="w">    </span><span class="n">osPriorityRealtime</span><span class="w">      </span><span class="o">=</span><span class="w"> </span><span class="o">+</span><span class="mi">3</span><span class="p">,</span><span class="w">          </span><span class="c1">///&lt; priority: realtime (highest)</span>
<span class="w">    </span><span class="n">osPriorityError</span><span class="w">         </span><span class="o">=</span><span class="w">  </span><span class="mh">0x84</span><span class="w">        </span><span class="c1">///&lt; system cannot determine priority or thread has illegal priority</span>
<span class="p">}</span><span class="w"> </span><span class="n">osPriority</span><span class="p">;</span>
</code></pre></div>
<p>在 TobudOS 中实现的时候进行了转化：</p>
<div class="highlight"><pre><span></span><code><span class="k">static</span><span class="w"> </span><span class="n">k_prio_t</span><span class="w"> </span><span class="nf">priority_cmsis2knl</span><span class="p">(</span><span class="n">osPriority</span><span class="w"> </span><span class="n">prio</span><span class="p">)</span>
<span class="p">{</span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">prio</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">osPriorityError</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="k">return</span><span class="w"> </span><span class="n">K_TASK_PRIO_INVALID</span><span class="p">;</span>
<span class="w">    </span><span class="p">}</span>

<span class="w">    </span><span class="k">return</span><span class="w"> </span><span class="p">(</span><span class="n">k_prio_t</span><span class="p">)(</span><span class="mi">3</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">prio</span><span class="p">);</span>
<span class="p">}</span>

<span class="k">static</span><span class="w"> </span><span class="n">osPriority</span><span class="w"> </span><span class="nf">priority_knl2cmsis</span><span class="p">(</span><span class="n">k_prio_t</span><span class="w"> </span><span class="n">prio</span><span class="p">)</span>
<span class="p">{</span>
<span class="w">    </span><span class="k">return</span><span class="w"> </span><span class="p">(</span><span class="n">osPriority</span><span class="p">)(</span><span class="mi">3</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">prio</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div>
<p>比如创建线程时设置为 osPriorityNormal=0，则<font color="red"><strong>实际设置的任务优先级为 3</strong></font>。</p>
<h2 id="23">2.3. 通用等待函数</h2>
<p>CMSIS-RTOS 提供的等待函数 API 如下：</p>
<table>
<thead>
<tr>
<th align="center">API</th>
<th align="center">描述</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">osDelay</td>
<td align="center">等待指定的时间</td>
</tr>
<tr>
<td align="center">osWait（可选）</td>
<td align="center">等待信号、消息、邮箱的某个事件</td>
</tr>
</tbody>
</table>
<ul>
<li><code>osDelay</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osDelay</span><span class="p">(</span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">millisec</span><span class="p">);</span>
</code></pre></div>
<p>返回值：osStatus。</p>
<h2 id="24">2.4. 软件定时器管理</h2>
<p>CMSIS-RTOS API 提供的存储定时器参数的结构体如下：</p>
<div class="highlight"><pre><span></span><code><span class="k">typedef</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">os_timer_def</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="n">os_ptimer</span><span class="w">                 </span><span class="n">cb</span><span class="p">;</span><span class="w">   </span><span class="c1">///&lt; start address of a timer function</span>
<span class="w">    </span><span class="n">k_timer_t</span><span class="w">                </span><span class="o">*</span><span class="n">timer</span><span class="p">;</span>
<span class="p">}</span><span class="w"> </span><span class="n">osTimerDef_t</span><span class="p">;</span>
</code></pre></div>
<p>CMSIS-RTOS API 提供的定义一个软件定时器的宏定义如下：</p>
<div class="highlight"><pre><span></span><code><span class="cp">#define osTimerDef(name, function)  \</span>
<span class="cp">    k_timer_t timer_handler_##name; \</span>
<span class="cp">    const osTimerDef_t os_timer_def_##name = \</span>
<span class="cp">        { (os_ptimer)(function), (&amp;(timer_handler_##name)) }</span>
</code></pre></div>
<p>CMSIS-RTOS API 定义的获取软件定时器参数结构体的宏如下：</p>
<div class="highlight"><pre><span></span><code><span class="cp">#define osTimer(name) \</span>
<span class="cp">    &amp;os_timer_def_##name</span>
</code></pre></div>
<p>CMSIS-RTOS API 提供的软件定时器管理 API 如下：</p>
<table>
<thead>
<tr>
<th align="center">API</th>
<th align="center">描述</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">osTimerCreate</td>
<td align="center">创建一个软件定时器</td>
</tr>
<tr>
<td align="center">osTimerStart</td>
<td align="center">启动软件定时器</td>
</tr>
<tr>
<td align="center">osTimerStop</td>
<td align="center">停止软件定时器</td>
</tr>
<tr>
<td align="center">osTimerDelete</td>
<td align="center">删除软件定时器</td>
</tr>
</tbody>
</table>
<ul>
<li><code>osTimerCreate</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="n">osTimerId</span><span class="w"> </span><span class="nf">osTimerCreate</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="n">osTimerDef_t</span><span class="w"> </span><span class="o">*</span><span class="n">timer_def</span><span class="p">,</span><span class="w"> </span><span class="n">os_timer_type</span><span class="w"> </span><span class="n">type</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">argument</span><span class="p">);</span>
</code></pre></div>
<p>其中 osTimerId 被定义为 k_timer_t 指针类型：</p>
<div class="highlight"><pre><span></span><code><span class="k">typedef</span><span class="w"> </span><span class="n">k_timer_t</span><span class="w"> </span><span class="o">*</span><span class="n">osTimerId</span><span class="p">;</span>
</code></pre></div>
<p>type 参数为 os_timer_type 类型，表示软件定时器的类型为单次触发或者周期触发：</p>
<div class="highlight"><pre><span></span><code><span class="k">typedef</span><span class="w"> </span><span class="k">enum</span><span class="w">  </span><span class="p">{</span>
<span class="w">    </span><span class="n">osTimerOnce</span><span class="w">             </span><span class="o">=</span><span class="w">     </span><span class="mi">0</span><span class="p">,</span><span class="w">       </span><span class="c1">///&lt; one-shot timer</span>
<span class="w">    </span><span class="n">osTimerPeriodic</span><span class="w">         </span><span class="o">=</span><span class="w">     </span><span class="mi">1</span><span class="w">        </span><span class="c1">///&lt; repeating timer</span>
<span class="p">}</span><span class="w"> </span><span class="n">os_timer_type</span><span class="p">;</span>
</code></pre></div>
<ul>
<li><code>osTimerStart</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osTimerStart</span><span class="p">(</span><span class="n">osTimerId</span><span class="w"> </span><span class="n">timer_id</span><span class="p">,</span><span class="w"> </span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">millisec</span><span class="p">);</span>
</code></pre></div>
<p>返回值：osStatus。</p>
<ul>
<li><code>osTimerStop</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="n">osTimerStop</span><span class="p">(</span><span class="n">osTimerId</span><span class="w"> </span><span class="n">timer_id</span><span class="p">)</span>
</code></pre></div>
<p>返回值：osStatus。</p>
<ul>
<li><code>osTimerDelete</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osTimerDelete</span><span class="p">(</span><span class="n">osTimerId</span><span class="w"> </span><span class="n">timer_id</span><span class="p">);</span>
</code></pre></div>
<p>返回值：osStatus。</p>
<h2 id="25">2.5. 信号量管理</h2>
<p>CMSIS-RTOS API 提供的存储信号量参数的结构体如下：</p>
<div class="highlight"><pre><span></span><code><span class="k">typedef</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">os_semaphore_def</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="kt">uint32_t</span><span class="w">                    </span><span class="n">dummy</span><span class="p">;</span><span class="w">  </span><span class="c1">///&lt; dummy value.</span>
<span class="w">    </span><span class="n">k_sem_t</span><span class="w">                    </span><span class="o">*</span><span class="n">sem</span><span class="p">;</span>
<span class="p">}</span><span class="w"> </span><span class="n">osSemaphoreDef_t</span><span class="p">;</span>
</code></pre></div>
<p>CMSIS-RTOS API 提供的定义一个信号量的宏定义如下：</p>
<div class="highlight"><pre><span></span><code><span class="cp">#define osSemaphoreDef(name)  \</span>
<span class="cp">    k_sem_t sem_handler_##name; \</span>
<span class="cp">    const osSemaphoreDef_t os_semaphore_def_##name = { 0, (&amp;(sem_handler_##name)) }</span>
</code></pre></div>
<p>CMSIS-RTOS API 定义的获取信号量参数结构体的宏如下：</p>
<div class="highlight"><pre><span></span><code><span class="cp">#define osSemaphore(name)  \</span>
<span class="cp">    &amp;os_semaphore_def_##name</span>
</code></pre></div>
<p>CMSIS-RTOS API 提供的信号量管理 API 如下：</p>
<table>
<thead>
<tr>
<th align="center">API</th>
<th align="center">描述</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">osSemaphoreCreate</td>
<td align="center">创建一个信号量</td>
</tr>
<tr>
<td align="center">osSemaphoreWait</td>
<td align="center">等待信号量</td>
</tr>
<tr>
<td align="center">osSemaphoreRelease</td>
<td align="center">释放信号量</td>
</tr>
<tr>
<td align="center">osSemaphoreDelete</td>
<td align="center">删除信号量</td>
</tr>
</tbody>
</table>
<ul>
<li><code>osSemaphoreCreate</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="n">osSemaphoreId</span><span class="w"> </span><span class="nf">osSemaphoreCreate</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="n">osSemaphoreDef_t</span><span class="w"> </span><span class="o">*</span><span class="n">semaphore_def</span><span class="p">,</span><span class="w"> </span><span class="kt">int32_t</span><span class="w"> </span><span class="n">count</span><span class="p">);</span>
</code></pre></div>
<p>其中 osSemaphoreId 被定义为 k_sem_t 指针类型：</p>
<div class="highlight"><pre><span></span><code><span class="k">typedef</span><span class="w"> </span><span class="n">k_sem_t</span><span class="w"> </span><span class="o">*</span><span class="n">osSemaphoreId</span><span class="p">;</span>
</code></pre></div>
<ul>
<li><code>osSemaphoreWait</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="kt">int32_t</span><span class="w"> </span><span class="nf">osSemaphoreWait</span><span class="p">(</span><span class="n">osSemaphoreId</span><span class="w"> </span><span class="n">semaphore_id</span><span class="p">,</span><span class="w"> </span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">millisec</span><span class="p">);</span>
</code></pre></div>
<p>返回值：int32_t，正常返回当前 count 数，失败返回 -1。</p>
<p>如果需要阻塞延时，参数应该设置为 CMSIS-RTOS API 提供的宏定义 osWaitForever：</p>
<div class="highlight"><pre><span></span><code><span class="cp">#define osWaitForever     0xFFFFFFFF     </span><span class="c1">///&lt; wait forever timeout value</span>
</code></pre></div>
<ul>
<li><code>osSemaphoreRelease</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osSemaphoreRelease</span><span class="p">(</span><span class="n">osSemaphoreId</span><span class="w"> </span><span class="n">semaphore_id</span><span class="p">);</span>
</code></pre></div>
<p>返回值：osStatus。</p>
<ul>
<li><code>osSemaphoreDelete</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osSemaphoreDelete</span><span class="p">(</span><span class="n">osSemaphoreId</span><span class="w"> </span><span class="n">semaphore_id</span><span class="p">);</span>
</code></pre></div>
<p>返回值：osStatus。</p>
<h2 id="26">2.6. 互斥锁管理</h2>
<p>CMSIS-RTOS API 提供的存储互斥锁参数的结构体如下：</p>
<div class="highlight"><pre><span></span><code><span class="k">typedef</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">os_mutex_def</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="kt">uint32_t</span><span class="w">                    </span><span class="n">dummy</span><span class="p">;</span><span class="w">  </span><span class="c1">///&lt; dummy value.</span>
<span class="w">    </span><span class="n">k_mutex_t</span><span class="w">                  </span><span class="o">*</span><span class="n">mutex</span><span class="p">;</span>
<span class="p">}</span><span class="w"> </span><span class="n">osMutexDef_t</span><span class="p">;</span>
</code></pre></div>
<p>CMSIS-RTOS API 提供的定义一个互斥锁的宏定义如下：</p>
<div class="highlight"><pre><span></span><code><span class="cp">#define osMutexDef(name)  \</span>
<span class="cp">    k_mutex_t mutex_handler_##name; \</span>
<span class="cp">    const osMutexDef_t os_mutex_def_##name = { 0, (&amp;(mutex_handler_##name)) }</span>
</code></pre></div>
<p>CMSIS-RTOS API 定义的获取互斥锁参数结构体的宏如下：</p>
<div class="highlight"><pre><span></span><code><span class="cp">#define osMutex(name)  \</span>
<span class="cp">    &amp;os_mutex_def_##name</span>
</code></pre></div>
<p>CMSIS-RTOS API 提供的互斥锁管理 API 如下：</p>
<table>
<thead>
<tr>
<th align="center">API</th>
<th align="center">描述</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">osMutexCreate</td>
<td align="center">创建一个互斥锁</td>
</tr>
<tr>
<td align="center">osMutexWait</td>
<td align="center">等待获取互斥锁</td>
</tr>
<tr>
<td align="center">osMutexRelease</td>
<td align="center">释放互斥锁</td>
</tr>
<tr>
<td align="center">osMutexDelete</td>
<td align="center">删除互斥锁</td>
</tr>
</tbody>
</table>
<ul>
<li><code>osMutexCreate</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="n">osMutexId</span><span class="w"> </span><span class="nf">osMutexCreate</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="n">osMutexDef_t</span><span class="w"> </span><span class="o">*</span><span class="n">mutex_def</span><span class="p">);</span>
</code></pre></div>
<p>其中 osMutexId 被定义为 k_mutex_t 指针类型：</p>
<div class="highlight"><pre><span></span><code><span class="k">typedef</span><span class="w"> </span><span class="n">k_mutex_t</span><span class="w"> </span><span class="o">*</span><span class="n">osMutexId</span><span class="p">;</span>
</code></pre></div>
<ul>
<li><code>osMutexWait</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osMutexWait</span><span class="p">(</span><span class="n">osMutexId</span><span class="w"> </span><span class="n">mutex_id</span><span class="p">,</span><span class="w"> </span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">millisec</span><span class="p">);</span>
</code></pre></div>
<p>返回值：osStatus。</p>
<p>如果需要阻塞延时，参数应该设置为 CMSIS-RTOS API 提供的宏定义 osWaitForever：</p>
<div class="highlight"><pre><span></span><code><span class="cp">#define osWaitForever     0xFFFFFFFF     </span><span class="c1">///&lt; wait forever timeout value</span>
</code></pre></div>
<ul>
<li><code>osMutexRelease</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osMutexRelease</span><span class="p">(</span><span class="n">osMutexId</span><span class="w"> </span><span class="n">mutex_id</span><span class="p">);</span>
</code></pre></div>
<p>返回值：osStatus。</p>
<ul>
<li><code>osMutexDelete</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osMutexDelete</span><span class="p">(</span><span class="n">osMutexId</span><span class="w"> </span><span class="n">mutex_id</span><span class="p">);</span>
</code></pre></div>
<p>返回值：osStatus。</p>
<h2 id="27">2.7. 静态内存池管理</h2>
<p>CMSIS-RTOS API 提供的存储静态内存池参数的结构体如下：</p>
<div class="highlight"><pre><span></span><code><span class="k">typedef</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">os_pool_def</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="kt">uint32_t</span><span class="w">                    </span><span class="n">pool_sz</span><span class="p">;</span><span class="w">    </span><span class="c1">///&lt; number of items (elements) in the pool</span>
<span class="w">    </span><span class="kt">uint32_t</span><span class="w">                    </span><span class="n">item_sz</span><span class="p">;</span><span class="w">    </span><span class="c1">///&lt; size of an item</span>
<span class="w">    </span><span class="kt">void</span><span class="w">                       </span><span class="o">*</span><span class="n">pool</span><span class="p">;</span><span class="w">       </span><span class="c1">///&lt; pointer to memory for pool</span>
<span class="w">    </span><span class="n">k_mmblk_pool_t</span><span class="w">             </span><span class="o">*</span><span class="n">mmblk_pool</span><span class="p">;</span><span class="w"> </span><span class="c1">///&lt; memory blk pool handler</span>
<span class="p">}</span><span class="w"> </span><span class="n">osPoolDef_t</span><span class="p">;</span>
</code></pre></div>
<p>CMSIS-RTOS API 提供的定义一个互斥锁的宏定义如下：</p>
<div class="highlight"><pre><span></span><code><span class="cp">#define osPoolDef(name, no, type)   \</span>
<span class="cp">    k_mmblk_pool_t mmblk_pool_handler_##name; \</span>
<span class="cp">    uint8_t mmblk_pool_buf_##name[(no) * sizeof(type)]; \</span>
<span class="cp">    const osPoolDef_t os_pool_def_##name = \</span>
<span class="cp">        { (no), sizeof(type), (&amp;((mmblk_pool_buf_##name)[0])), (&amp;(mmblk_pool_handler_##name)) }</span>
</code></pre></div>
<p>CMSIS-RTOS API 定义的获取互斥锁参数结构体的宏如下：</p>
<div class="highlight"><pre><span></span><code><span class="cp">#define osPool(name) \</span>
<span class="cp">    &amp;os_pool_def_##name</span>
</code></pre></div>
<p>CMSIS-RTOS API 提供的互斥锁管理 API 如下：</p>
<table>
<thead>
<tr>
<th align="center">API</th>
<th align="center">描述</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">osPoolCreate</td>
<td align="center">创建一块固定大小的静态内存池</td>
</tr>
<tr>
<td align="center">osPoolAlloc</td>
<td align="center">申请分配内存</td>
</tr>
<tr>
<td align="center">osPoolCAlloc</td>
<td align="center">申请分配一块内存并全部初始化为 0</td>
</tr>
<tr>
<td align="center">osPoolFree</td>
<td align="center">申请回收内存</td>
</tr>
</tbody>
</table>
<ul>
<li><code>osPoolCreate</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="n">osPoolId</span><span class="w"> </span><span class="nf">osPoolCreate</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="n">osPoolDef_t</span><span class="w"> </span><span class="o">*</span><span class="n">pool_def</span><span class="p">);</span>
</code></pre></div>
<p>其中 osPoolId 被定义为 k_mmblk_pool_t 指针类型：</p>
<div class="highlight"><pre><span></span><code><span class="k">typedef</span><span class="w"> </span><span class="n">k_mmblk_pool_t</span><span class="w"> </span><span class="o">*</span><span class="n">osPoolId</span><span class="p">;</span>
</code></pre></div>
<ul>
<li><code>osPoolAlloc</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="nf">osPoolAlloc</span><span class="p">(</span><span class="n">osPoolId</span><span class="w"> </span><span class="n">pool_id</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><code>osPoolCAlloc</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="nf">osPoolCAlloc</span><span class="p">(</span><span class="n">osPoolId</span><span class="w"> </span><span class="n">pool_id</span><span class="p">);</span>
</code></pre></div>
<ul>
<li><code>osPoolFree</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osPoolFree</span><span class="p">(</span><span class="n">osPoolId</span><span class="w"> </span><span class="n">pool_id</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">block</span><span class="p">);</span>
</code></pre></div>
<p>返回值：osStatus。</p>
<h2 id="28">2.8. 消息队列管理</h2>
<p>CMSIS-RTOS API 提供的存储消息队列参数的结构体如下：</p>
<div class="highlight"><pre><span></span><code><span class="k">typedef</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">os_messageQ_def</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="kt">uint32_t</span><span class="w">                    </span><span class="n">queue_sz</span><span class="p">;</span><span class="w">   </span><span class="c1">///&lt; number of elements in the queue</span>
<span class="w">    </span><span class="kt">uint32_t</span><span class="w">                    </span><span class="n">item_sz</span><span class="p">;</span><span class="w">    </span><span class="c1">///&lt; size of an item</span>
<span class="w">    </span><span class="kt">void</span><span class="w">                       </span><span class="o">*</span><span class="n">pool</span><span class="p">;</span><span class="w">       </span><span class="c1">///&lt; memory array for messages</span>
<span class="w">    </span><span class="n">k_msg_q_t</span><span class="w">                  </span><span class="o">*</span><span class="n">queue</span><span class="p">;</span><span class="w">      </span><span class="c1">///&lt; queue handler</span>
<span class="p">}</span><span class="w"> </span><span class="n">osMessageQDef_t</span><span class="p">;</span>
</code></pre></div>
<p>CMSIS-RTOS API 提供的定义一个消息队列的宏定义如下：</p>
<div class="highlight"><pre><span></span><code><span class="cp">#define osMessageQDef(name, queue_sz, type)   \</span>
<span class="cp">    k_msg_q_t msg_q_handler_##name; \</span>
<span class="cp">    const osMessageQDef_t os_messageQ_def_##name = \</span>
<span class="cp">        { (queue_sz), sizeof(type), NULL, (&amp;(msg_q_handler_##name)) }</span>
</code></pre></div>
<p>CMSIS-RTOS API 定义的获取消息队列参数结构体的宏如下：</p>
<div class="highlight"><pre><span></span><code><span class="cp">#define osMessageQ(name) \</span>
<span class="cp">    &amp;os_messageQ_def_##name</span>
</code></pre></div>
<p>CMSIS-RTOS API 提供的消息队列管理 API 如下：</p>
<table>
<thead>
<tr>
<th align="center">API</th>
<th align="center">描述</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">osMessageCreate</td>
<td align="center">初始化一个消息队列</td>
</tr>
<tr>
<td align="center">osMessagePut</td>
<td align="center">向消息队列中加入数据</td>
</tr>
<tr>
<td align="center">osMessageGet</td>
<td align="center">从消息队列中取出数据</td>
</tr>
</tbody>
</table>
<ul>
<li><code>osMessageCreate</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="n">osMessageQId</span><span class="w"> </span><span class="nf">osMessageCreate</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="n">osMessageQDef_t</span><span class="w"> </span><span class="o">*</span><span class="n">queue_def</span><span class="p">,</span><span class="w"> </span><span class="n">osThreadId</span><span class="w"> </span><span class="n">thread_id</span><span class="p">);</span>
</code></pre></div>
<p>其中 osMessageQId 被定义为 k_msg_q_t 指针类型：</p>
<div class="highlight"><pre><span></span><code><span class="k">typedef</span><span class="w"> </span><span class="n">k_msg_q_t</span><span class="w"> </span><span class="o">*</span><span class="n">osMessageQId</span><span class="p">;</span>
</code></pre></div>
<ul>
<li><code>osMessagePut</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="n">osStatus</span><span class="w"> </span><span class="nf">osMessagePut</span><span class="p">(</span><span class="n">osMessageQId</span><span class="w"> </span><span class="n">queue_id</span><span class="p">,</span><span class="w"> </span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">info</span><span class="p">,</span><span class="w"> </span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">millisec</span><span class="p">);</span>
</code></pre></div>
<p>返回值：osStatus。</p>
<blockquote>
<p>因为 TobudOS 中消息队列实现机制的不同，此 API 中的 millisec 参数未用到。</p>
</blockquote>
<ul>
<li><code>osMessageGet</code></li>
</ul>
<div class="highlight"><pre><span></span><code><span class="n">osEvent</span><span class="w"> </span><span class="nf">osMessageGet</span><span class="p">(</span><span class="n">osMessageQId</span><span class="w"> </span><span class="n">queue_id</span><span class="p">,</span><span class="w"> </span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">millisec</span><span class="p">);</span>
</code></pre></div>
<p>返回值：osEvent，其中包含了事件信息和错误码，以及消息队列收到的值。</p>
<p>如果需要阻塞延时，参数应该设置为 CMSIS-RTOS API 提供的宏定义 osWaitForever：</p>
<div class="highlight"><pre><span></span><code><span class="cp">#define osWaitForever     0xFFFFFFFF     </span><span class="c1">///&lt; wait forever timeout value</span>
</code></pre></div>
<h1 id="3">3. 使用示例</h1>
<h2 id="31">3.1. 任务创建示例</h2>
<div class="highlight"><pre><span></span><code><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;cmsis_os.h&gt;</span>

<span class="kt">void</span><span class="w"> </span><span class="nf">task1_entry</span><span class="p">(</span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">arg</span><span class="p">)</span>
<span class="p">{</span>
<span class="w">    </span><span class="k">while</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="w">    </span><span class="p">{</span>
<span class="w">        </span><span class="n">printf</span><span class="p">(</span><span class="s">&quot;task1 is running...</span><span class="se">\r\n</span><span class="s">&quot;</span><span class="p">);</span>
<span class="w">        </span><span class="n">osDelay</span><span class="p">(</span><span class="mi">1000</span><span class="p">);</span>
<span class="w">    </span><span class="p">}</span>
<span class="p">}</span>
<span class="n">osThreadDef</span><span class="p">(</span><span class="n">task1_entry</span><span class="p">,</span><span class="w"> </span><span class="n">osPriorityNormal</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">512</span><span class="p">);</span>

<span class="kt">void</span><span class="w"> </span><span class="nf">task2_entry</span><span class="p">(</span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">arg</span><span class="p">)</span>
<span class="p">{</span>

<span class="w">    </span><span class="k">while</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="w">    </span><span class="p">{</span>
<span class="w">        </span><span class="n">printf</span><span class="p">(</span><span class="s">&quot;task2 is running...</span><span class="se">\r\n</span><span class="s">&quot;</span><span class="p">);</span>
<span class="w">        </span><span class="n">osDelay</span><span class="p">(</span><span class="mi">1000</span><span class="p">);</span>
<span class="w">    </span><span class="p">}</span>
<span class="p">}</span>
<span class="n">osThreadDef</span><span class="p">(</span><span class="n">task2_entry</span><span class="p">,</span><span class="w"> </span><span class="n">osPriorityNormal</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">512</span><span class="p">);</span>

<span class="kt">void</span><span class="w"> </span><span class="nf">application_entry</span><span class="p">(</span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">arg</span><span class="p">)</span>
<span class="p">{</span>

<span class="w">    </span><span class="n">osThreadCreate</span><span class="p">(</span><span class="n">osThread</span><span class="p">(</span><span class="n">task1_entry</span><span class="p">),</span><span class="w"> </span><span class="nb">NULL</span><span class="p">);</span>
<span class="w">    </span><span class="n">osThreadCreate</span><span class="p">(</span><span class="n">osThread</span><span class="p">(</span><span class="n">task2_entry</span><span class="p">),</span><span class="w"> </span><span class="nb">NULL</span><span class="p">);</span>

<span class="w">    </span><span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div>
<p>任务运行结果如下：</p>
<div class="highlight"><pre><span></span><code><span class="n">task1</span><span class="w"> </span><span class="n">is</span><span class="w"> </span><span class="n">running</span><span class="p">...</span>
<span class="n">task2</span><span class="w"> </span><span class="n">is</span><span class="w"> </span><span class="n">running</span><span class="p">...</span>
<span class="n">task1</span><span class="w"> </span><span class="n">is</span><span class="w"> </span><span class="n">running</span><span class="p">...</span>
<span class="n">task2</span><span class="w"> </span><span class="n">is</span><span class="w"> </span><span class="n">running</span><span class="p">...</span>
<span class="n">task1</span><span class="w"> </span><span class="n">is</span><span class="w"> </span><span class="n">running</span><span class="p">...</span>
<span class="n">task2</span><span class="w"> </span><span class="n">is</span><span class="w"> </span><span class="n">running</span><span class="p">...</span>
</code></pre></div>
<h2 id="32">3.2. 软件定时器使用示例</h2>
<div class="highlight"><pre><span></span><code><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;cmsis_os.h&gt;</span>

<span class="kt">void</span><span class="w"> </span><span class="nf">timer1_cb</span><span class="p">(</span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">arg</span><span class="p">)</span>
<span class="p">{</span>
<span class="w">    </span><span class="n">printf</span><span class="p">(</span><span class="s">&quot;timer1 is timeout!</span><span class="se">\r\n</span><span class="s">&quot;</span><span class="p">);</span>
<span class="p">}</span>

<span class="kt">void</span><span class="w"> </span><span class="nf">timer2_cb</span><span class="p">(</span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">arg</span><span class="p">)</span>
<span class="p">{</span>
<span class="w">    </span><span class="n">printf</span><span class="p">(</span><span class="s">&quot;timer2 is timeout!</span><span class="se">\r\n</span><span class="s">&quot;</span><span class="p">);</span>
<span class="p">}</span>

<span class="n">osTimerDef</span><span class="p">(</span><span class="n">timer1</span><span class="p">,</span><span class="w"> </span><span class="n">timer1_cb</span><span class="p">);</span>
<span class="n">osTimerDef</span><span class="p">(</span><span class="n">timer2</span><span class="p">,</span><span class="w"> </span><span class="n">timer2_cb</span><span class="p">);</span>

<span class="kt">void</span><span class="w"> </span><span class="nf">application_entry</span><span class="p">(</span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">arg</span><span class="p">)</span>
<span class="p">{</span>
<span class="w">    </span><span class="n">osTimerId</span><span class="w"> </span><span class="n">timer1</span><span class="p">;</span>
<span class="w">    </span><span class="n">osTimerId</span><span class="w"> </span><span class="n">timer2</span><span class="p">;</span>

<span class="w">    </span><span class="n">timer1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">osTimerCreate</span><span class="p">(</span><span class="n">osTimer</span><span class="p">(</span><span class="n">timer1</span><span class="p">),</span><span class="w"> </span><span class="n">osTimerOnce</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="p">);</span>
<span class="w">    </span><span class="n">timer2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">osTimerCreate</span><span class="p">(</span><span class="n">osTimer</span><span class="p">(</span><span class="n">timer2</span><span class="p">),</span><span class="w"> </span><span class="n">osTimerPeriodic</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="p">);</span>

<span class="w">    </span><span class="n">osTimerStart</span><span class="p">(</span><span class="n">timer1</span><span class="p">,</span><span class="w"> </span><span class="mi">5000</span><span class="p">);</span>
<span class="w">    </span><span class="n">osTimerStart</span><span class="p">(</span><span class="n">timer2</span><span class="p">,</span><span class="w"> </span><span class="mi">1000</span><span class="p">);</span>

<span class="w">    </span><span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div>
<p>运行结果如下：</p>
<div class="highlight"><pre><span></span><code><span class="n">timer2</span><span class="w"> </span><span class="n">is</span><span class="w"> </span><span class="n">timeout</span><span class="o">!</span>
<span class="n">timer2</span><span class="w"> </span><span class="n">is</span><span class="w"> </span><span class="n">timeout</span><span class="o">!</span>
<span class="n">timer2</span><span class="w"> </span><span class="n">is</span><span class="w"> </span><span class="n">timeout</span><span class="o">!</span>
<span class="n">timer2</span><span class="w"> </span><span class="n">is</span><span class="w"> </span><span class="n">timeout</span><span class="o">!</span>
<span class="n">timer1</span><span class="w"> </span><span class="n">is</span><span class="w"> </span><span class="n">timeout</span><span class="o">!</span>
<span class="n">timer2</span><span class="w"> </span><span class="n">is</span><span class="w"> </span><span class="n">timeout</span><span class="o">!</span>
<span class="n">timer2</span><span class="w"> </span><span class="n">is</span><span class="w"> </span><span class="n">timeout</span><span class="o">!</span>
<span class="n">timer2</span><span class="w"> </span><span class="n">is</span><span class="w"> </span><span class="n">timeout</span><span class="o">!</span>
<span class="n">timer2</span><span class="w"> </span><span class="n">is</span><span class="w"> </span><span class="n">timeout</span><span class="o">!</span>
</code></pre></div>
<h2 id="33">3.3. 信号量使用示例</h2>
<div class="highlight"><pre><span></span><code><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;cmsis_os.h&gt;</span>

<span class="n">osSemaphoreId</span><span class="w"> </span><span class="n">sync_sem_id</span><span class="p">;</span>
<span class="n">osSemaphoreDef</span><span class="p">(</span><span class="n">sync_sem</span><span class="p">);</span>

<span class="kt">void</span><span class="w"> </span><span class="nf">task1_entry</span><span class="p">(</span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">arg</span><span class="p">)</span>
<span class="p">{</span>
<span class="w">    </span><span class="k">while</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="w">    </span><span class="p">{</span>
<span class="w">        </span><span class="n">printf</span><span class="p">(</span><span class="s">&quot;task1 is waiting sem forever...</span><span class="se">\r\n</span><span class="s">&quot;</span><span class="p">);</span>
<span class="w">        </span><span class="n">osSemaphoreWait</span><span class="p">(</span><span class="n">sync_sem_id</span><span class="p">,</span><span class="w"> </span><span class="n">osWaitForever</span><span class="p">);</span>
<span class="w">        </span><span class="n">printf</span><span class="p">(</span><span class="s">&quot;task1 get sem!</span><span class="se">\r\n</span><span class="s">&quot;</span><span class="p">);</span>
<span class="w">    </span><span class="p">}</span>
<span class="p">}</span>
<span class="n">osThreadDef</span><span class="p">(</span><span class="n">task1_entry</span><span class="p">,</span><span class="w"> </span><span class="n">osPriorityNormal</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">512</span><span class="p">);</span>

<span class="kt">void</span><span class="w"> </span><span class="nf">task2_entry</span><span class="p">(</span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">arg</span><span class="p">)</span>
<span class="p">{</span>

<span class="w">    </span><span class="k">while</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="w">    </span><span class="p">{</span>
<span class="w">        </span><span class="n">printf</span><span class="p">(</span><span class="s">&quot;task2 will release a sem...</span><span class="se">\r\n</span><span class="s">&quot;</span><span class="p">);</span>
<span class="w">        </span><span class="n">osSemaphoreRelease</span><span class="p">(</span><span class="n">sync_sem_id</span><span class="p">);</span>
<span class="w">        </span><span class="n">osDelay</span><span class="p">(</span><span class="mi">1000</span><span class="p">);</span>
<span class="w">    </span><span class="p">}</span>
<span class="p">}</span>
<span class="n">osThreadDef</span><span class="p">(</span><span class="n">task2_entry</span><span class="p">,</span><span class="w"> </span><span class="n">osPriorityNormal</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">512</span><span class="p">);</span>

<span class="kt">void</span><span class="w"> </span><span class="nf">application_entry</span><span class="p">(</span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">arg</span><span class="p">)</span>
<span class="p">{</span>
<span class="w">    </span><span class="n">sync_sem_id</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">osSemaphoreCreate</span><span class="p">(</span><span class="n">osSemaphore</span><span class="p">(</span><span class="n">sync_sem</span><span class="p">),</span><span class="w"> </span><span class="mi">0</span><span class="p">);</span>

<span class="w">    </span><span class="n">osThreadCreate</span><span class="p">(</span><span class="n">osThread</span><span class="p">(</span><span class="n">task1_entry</span><span class="p">),</span><span class="w"> </span><span class="nb">NULL</span><span class="p">);</span>
<span class="w">    </span><span class="n">osThreadCreate</span><span class="p">(</span><span class="n">osThread</span><span class="p">(</span><span class="n">task2_entry</span><span class="p">),</span><span class="w"> </span><span class="nb">NULL</span><span class="p">);</span>

<span class="w">    </span><span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div>
<p>运行结果为：</p>
<div class="highlight"><pre><span></span><code><span class="n">task1</span><span class="w"> </span><span class="n">is</span><span class="w"> </span><span class="n">waiting</span><span class="w"> </span><span class="n">sem</span><span class="w"> </span><span class="n">forever</span><span class="p">...</span>
<span class="n">task1</span><span class="w"> </span><span class="n">get</span><span class="w"> </span><span class="n">sem</span><span class="o">!</span>
<span class="n">task1</span><span class="w"> </span><span class="n">is</span><span class="w"> </span><span class="n">waiting</span><span class="w"> </span><span class="n">sem</span><span class="w"> </span><span class="n">forever</span><span class="p">...</span>
<span class="n">task2</span><span class="w"> </span><span class="n">will</span><span class="w"> </span><span class="n">release</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="n">sem</span><span class="p">...</span>
<span class="n">task1</span><span class="w"> </span><span class="n">get</span><span class="w"> </span><span class="n">sem</span><span class="o">!</span>
<span class="n">task1</span><span class="w"> </span><span class="n">is</span><span class="w"> </span><span class="n">waiting</span><span class="w"> </span><span class="n">sem</span><span class="w"> </span><span class="n">forever</span><span class="p">...</span>
<span class="n">task2</span><span class="w"> </span><span class="n">will</span><span class="w"> </span><span class="n">release</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="n">sem</span><span class="p">...</span>
<span class="n">task1</span><span class="w"> </span><span class="n">get</span><span class="w"> </span><span class="n">sem</span><span class="o">!</span>
<span class="n">task1</span><span class="w"> </span><span class="n">is</span><span class="w"> </span><span class="n">waiting</span><span class="w"> </span><span class="n">sem</span><span class="w"> </span><span class="n">forever</span><span class="p">...</span>
<span class="n">task2</span><span class="w"> </span><span class="n">will</span><span class="w"> </span><span class="n">release</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="n">sem</span><span class="p">...</span>
<span class="n">task1</span><span class="w"> </span><span class="n">get</span><span class="w"> </span><span class="n">sem</span><span class="o">!</span>
<span class="n">task1</span><span class="w"> </span><span class="n">is</span><span class="w"> </span><span class="n">waiting</span><span class="w"> </span><span class="n">sem</span><span class="w"> </span><span class="n">forever</span><span class="p">...</span>
<span class="n">task2</span><span class="w"> </span><span class="n">will</span><span class="w"> </span><span class="n">release</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="n">sem</span><span class="p">...</span>
<span class="n">task1</span><span class="w"> </span><span class="n">get</span><span class="w"> </span><span class="n">sem</span><span class="o">!</span>
<span class="n">task1</span><span class="w"> </span><span class="n">is</span><span class="w"> </span><span class="n">waiting</span><span class="w"> </span><span class="n">sem</span><span class="w"> </span><span class="n">forever</span><span class="p">...</span>
</code></pre></div>
<h2 id="34">3.4. 互斥锁使用示例</h2>
<div class="highlight"><pre><span></span><code><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;cmsis_os.h&gt;</span>

<span class="n">osMutexId</span><span class="w"> </span><span class="n">sync_mutex_id</span><span class="p">;</span>
<span class="n">osMutexDef</span><span class="p">(</span><span class="n">sync_mutex</span><span class="p">);</span>

<span class="kt">void</span><span class="w"> </span><span class="nf">task1_entry</span><span class="p">(</span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">arg</span><span class="p">)</span>
<span class="p">{</span>
<span class="w">    </span><span class="k">while</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="w">    </span><span class="p">{</span>
<span class="w">        </span><span class="n">osMutexWait</span><span class="p">(</span><span class="n">sync_mutex_id</span><span class="p">,</span><span class="w"> </span><span class="n">osWaitForever</span><span class="p">);</span>

<span class="w">        </span><span class="n">printf</span><span class="p">(</span><span class="s">&quot;task1 get mutex,doing sth...</span><span class="se">\r\n</span><span class="s">&quot;</span><span class="p">);</span>
<span class="w">        </span><span class="n">HAL_Delay</span><span class="p">(</span><span class="mi">1000</span><span class="p">);</span><span class="w">    </span><span class="c1">//死循环占用 CPU</span>
<span class="w">        </span><span class="n">printf</span><span class="p">(</span><span class="s">&quot;task1 finish do sth!</span><span class="se">\r\n</span><span class="s">&quot;</span><span class="p">);</span>

<span class="w">        </span><span class="n">osMutexRelease</span><span class="p">(</span><span class="n">sync_mutex_id</span><span class="p">);</span>

<span class="w">        </span><span class="n">osDelay</span><span class="p">(</span><span class="mi">1000</span><span class="p">);</span>
<span class="w">    </span><span class="p">}</span>
<span class="p">}</span>
<span class="n">osThreadDef</span><span class="p">(</span><span class="n">task1_entry</span><span class="p">,</span><span class="w"> </span><span class="n">osPriorityHigh</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">512</span><span class="p">);</span>

<span class="kt">void</span><span class="w"> </span><span class="nf">task2_entry</span><span class="p">(</span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">arg</span><span class="p">)</span>
<span class="p">{</span>

<span class="w">    </span><span class="k">while</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="w">    </span><span class="p">{</span>
<span class="w">        </span><span class="n">osMutexWait</span><span class="p">(</span><span class="n">sync_mutex_id</span><span class="p">,</span><span class="w"> </span><span class="n">osWaitForever</span><span class="p">);</span>

<span class="w">        </span><span class="n">printf</span><span class="p">(</span><span class="s">&quot;task2 get mutex,doing sth...</span><span class="se">\r\n</span><span class="s">&quot;</span><span class="p">);</span>
<span class="w">        </span><span class="n">HAL_Delay</span><span class="p">(</span><span class="mi">2000</span><span class="p">);</span><span class="w">    </span><span class="c1">//死循环占用 CPU</span>
<span class="w">        </span><span class="n">printf</span><span class="p">(</span><span class="s">&quot;task2 finish do sth!</span><span class="se">\r\n</span><span class="s">&quot;</span><span class="p">);</span>

<span class="w">        </span><span class="n">osMutexRelease</span><span class="p">(</span><span class="n">sync_mutex_id</span><span class="p">);</span>

<span class="w">        </span><span class="n">osDelay</span><span class="p">(</span><span class="mi">1000</span><span class="p">);</span>
<span class="w">    </span><span class="p">}</span>
<span class="p">}</span>
<span class="n">osThreadDef</span><span class="p">(</span><span class="n">task2_entry</span><span class="p">,</span><span class="w"> </span><span class="n">osPriorityNormal</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">512</span><span class="p">);</span>

<span class="kt">void</span><span class="w"> </span><span class="nf">application_entry</span><span class="p">(</span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">arg</span><span class="p">)</span>
<span class="p">{</span>
<span class="w">    </span><span class="n">sync_mutex_id</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">osMutexCreate</span><span class="p">(</span><span class="n">osMutex</span><span class="p">(</span><span class="n">sync_mutex</span><span class="p">));</span>

<span class="w">    </span><span class="n">osThreadCreate</span><span class="p">(</span><span class="n">osThread</span><span class="p">(</span><span class="n">task1_entry</span><span class="p">),</span><span class="w"> </span><span class="nb">NULL</span><span class="p">);</span>
<span class="w">    </span><span class="n">osThreadCreate</span><span class="p">(</span><span class="n">osThread</span><span class="p">(</span><span class="n">task2_entry</span><span class="p">),</span><span class="w"> </span><span class="nb">NULL</span><span class="p">);</span>

<span class="w">    </span><span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div>
<p>运行结果为：</p>
<div class="highlight"><pre><span></span><code><span class="n">task1</span><span class="w"> </span><span class="n">get</span><span class="w"> </span><span class="n">mutex</span><span class="p">,</span><span class="n">doing</span><span class="w"> </span><span class="n">sth</span><span class="p">...</span>
<span class="n">task1</span><span class="w"> </span><span class="n">finish</span><span class="w"> </span><span class="k">do</span><span class="w"> </span><span class="n">sth</span><span class="o">!</span>
<span class="n">task2</span><span class="w"> </span><span class="n">get</span><span class="w"> </span><span class="n">mutex</span><span class="p">,</span><span class="n">doing</span><span class="w"> </span><span class="n">sth</span><span class="p">...</span>
<span class="n">task2</span><span class="w"> </span><span class="n">finish</span><span class="w"> </span><span class="k">do</span><span class="w"> </span><span class="n">sth</span><span class="o">!</span>
<span class="n">task1</span><span class="w"> </span><span class="n">get</span><span class="w"> </span><span class="n">mutex</span><span class="p">,</span><span class="n">doing</span><span class="w"> </span><span class="n">sth</span><span class="p">...</span>
<span class="n">task1</span><span class="w"> </span><span class="n">finish</span><span class="w"> </span><span class="k">do</span><span class="w"> </span><span class="n">sth</span><span class="o">!</span>
<span class="n">task1</span><span class="w"> </span><span class="n">get</span><span class="w"> </span><span class="n">mutex</span><span class="p">,</span><span class="n">doing</span><span class="w"> </span><span class="n">sth</span><span class="p">...</span>
<span class="n">task1</span><span class="w"> </span><span class="n">finish</span><span class="w"> </span><span class="k">do</span><span class="w"> </span><span class="n">sth</span><span class="o">!</span>
<span class="n">task2</span><span class="w"> </span><span class="n">get</span><span class="w"> </span><span class="n">mutex</span><span class="p">,</span><span class="n">doing</span><span class="w"> </span><span class="n">sth</span><span class="p">...</span>
</code></pre></div>
<h2 id="35">3.5. 动态内存使用示例</h2>
<div class="highlight"><pre><span></span><code><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;cmsis_os.h&gt;</span>

<span class="k">typedef</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">blk_st</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="kt">int</span><span class="w">   </span><span class="n">id</span><span class="p">;</span>
<span class="w">    </span><span class="kt">char</span><span class="o">*</span><span class="w"> </span><span class="n">payload</span><span class="p">;</span>
<span class="p">}</span><span class="w"> </span><span class="n">blk_t</span><span class="p">;</span>

<span class="cp">#define MMBLK_BLK_NUM 10</span>

<span class="n">osPoolDef</span><span class="w"> </span><span class="p">(</span><span class="n">MemPool</span><span class="p">,</span><span class="w"> </span><span class="n">MMBLK_BLK_NUM</span><span class="p">,</span><span class="w"> </span><span class="n">blk_t</span><span class="p">);</span>
<span class="n">osPoolId</span><span class="w"> </span><span class="n">mem_pool_id</span><span class="p">;</span>

<span class="kt">void</span><span class="w"> </span><span class="nf">task1_entry</span><span class="p">(</span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">arg</span><span class="p">)</span>
<span class="p">{</span>

<span class="w">    </span><span class="n">blk_t</span><span class="w"> </span><span class="o">*</span><span class="n">ptr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">;</span>
<span class="w">    </span><span class="n">osStatus</span><span class="w"> </span><span class="n">err</span><span class="p">;</span>

<span class="w">    </span><span class="cm">/* 打印出一个块的大小 */</span>
<span class="w">    </span><span class="n">printf</span><span class="p">(</span><span class="s">&quot;block size is %d bytes</span><span class="se">\r\n</span><span class="s">&quot;</span><span class="p">,</span><span class="w"> </span><span class="k">sizeof</span><span class="p">(</span><span class="n">blk_t</span><span class="p">));</span>

<span class="w">    </span><span class="cm">/* 申请一个块 */</span>
<span class="w">    </span><span class="n">ptr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">osPoolAlloc</span><span class="p">(</span><span class="n">mem_pool_id</span><span class="p">);</span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">ptr</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="n">printf</span><span class="p">(</span><span class="s">&quot;a mmblk alloc fail</span><span class="se">\r\n</span><span class="s">&quot;</span><span class="p">);</span>
<span class="w">        </span><span class="k">return</span><span class="p">;</span>
<span class="w">    </span><span class="p">}</span>
<span class="w">    </span><span class="k">else</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="n">printf</span><span class="p">(</span><span class="s">&quot;a mmblk alloc success</span><span class="se">\r\n</span><span class="s">&quot;</span><span class="p">);</span>
<span class="w">    </span><span class="p">}</span>

<span class="w">    </span><span class="cm">/* 使用该块 */</span>
<span class="w">    </span><span class="n">ptr</span><span class="o">-&gt;</span><span class="n">id</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span>
<span class="w">    </span><span class="n">ptr</span><span class="o">-&gt;</span><span class="n">payload</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;hello&quot;</span><span class="p">;</span>
<span class="w">    </span><span class="n">printf</span><span class="p">(</span><span class="s">&quot;mmblk id:%d payload:%s</span><span class="se">\r\n</span><span class="s">&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">ptr</span><span class="o">-&gt;</span><span class="n">id</span><span class="p">,</span><span class="w"> </span><span class="n">ptr</span><span class="o">-&gt;</span><span class="n">payload</span><span class="p">);</span>

<span class="w">    </span><span class="cm">/* 使用完毕之后释放 */</span>
<span class="w">    </span><span class="n">err</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">osPoolFree</span><span class="p">(</span><span class="n">mem_pool_id</span><span class="p">,</span><span class="w"> </span><span class="n">ptr</span><span class="p">);</span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">err</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="n">osOK</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="n">printf</span><span class="p">(</span><span class="s">&quot;a mmblk free fail, err = %d</span><span class="se">\r\n</span><span class="s">&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">err</span><span class="p">);</span>
<span class="w">        </span><span class="k">return</span><span class="p">;</span>
<span class="w">    </span><span class="p">}</span>
<span class="w">    </span><span class="k">else</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="n">printf</span><span class="p">(</span><span class="s">&quot;a mmblk free success</span><span class="se">\r\n</span><span class="s">&quot;</span><span class="p">);</span>
<span class="w">    </span><span class="p">}</span>

<span class="w">    </span><span class="k">while</span><span class="w"> </span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="n">tos_task_delay</span><span class="p">(</span><span class="mi">1000</span><span class="p">);</span>
<span class="w">    </span><span class="p">}</span>
<span class="p">}</span>

<span class="cp">#define STK_SIZE_TASK1      1024</span>
<span class="n">osThreadDef</span><span class="p">(</span><span class="n">task1_entry</span><span class="p">,</span><span class="w"> </span><span class="n">osPriorityNormal</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">STK_SIZE_TASK1</span><span class="p">);</span>

<span class="kt">void</span><span class="w"> </span><span class="nf">application_entry</span><span class="p">(</span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">arg</span><span class="p">)</span>
<span class="p">{</span>
<span class="w">    </span><span class="c1">//初始化静态内存池</span>
<span class="w">    </span><span class="n">mem_pool_id</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">osPoolCreate</span><span class="p">(</span><span class="n">osPool</span><span class="p">(</span><span class="n">MemPool</span><span class="p">));</span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">mem_pool_id</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="n">printf</span><span class="p">(</span><span class="s">&quot;mmblk pool create fail</span><span class="se">\r\n</span><span class="s">&quot;</span><span class="p">);</span>
<span class="w">        </span><span class="k">return</span><span class="p">;</span>
<span class="w">    </span><span class="p">}</span>
<span class="w">    </span><span class="k">else</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="n">printf</span><span class="p">(</span><span class="s">&quot;mmblk pool create success</span><span class="se">\r\n</span><span class="s">&quot;</span><span class="p">);</span>
<span class="w">    </span><span class="p">}</span>

<span class="w">    </span><span class="c1">//创建任务</span>
<span class="w">    </span><span class="n">osThreadCreate</span><span class="p">(</span><span class="n">osThread</span><span class="p">(</span><span class="n">task1_entry</span><span class="p">),</span><span class="w"> </span><span class="nb">NULL</span><span class="p">);</span>

<span class="w">    </span><span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div>
<p>运行结果为：</p>
<div class="highlight"><pre><span></span><code>mmblk pool create success
block size is 8 bytes
a mmblk alloc success
mmblk id:1 payload:hello
a mmblk free success
</code></pre></div>
<h2 id="36">3.6. 消息队列使用示例</h2>
<div class="highlight"><pre><span></span><code><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;cmsis_os.h&gt;</span>

<span class="cp">#define STK_SIZE_TASK_RECEIVER      512</span>
<span class="cp">#define STK_SIZE_TASK_SENDER        512</span>

<span class="cp">#define MESSAGE_MAX     10</span>

<span class="n">osMessageQId</span><span class="w"> </span><span class="n">msg_q_id</span><span class="p">;</span>
<span class="n">osMessageQDef</span><span class="p">(</span><span class="n">msg_q</span><span class="p">,</span><span class="n">MESSAGE_MAX</span><span class="p">,</span><span class="kt">uint32_t</span><span class="p">);</span>

<span class="kt">void</span><span class="w"> </span><span class="nf">task_receiver_entry</span><span class="p">(</span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">arg</span><span class="p">)</span>
<span class="p">{</span>
<span class="w">    </span><span class="n">osEvent</span><span class="w"> </span><span class="n">event</span><span class="p">;</span>
<span class="w">    </span><span class="n">osStatus</span><span class="w"> </span><span class="n">ret</span><span class="p">;</span>
<span class="w">    </span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">value</span><span class="p">;</span>

<span class="w">    </span><span class="k">while</span><span class="w"> </span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="w">    </span><span class="p">{</span>
<span class="w">        </span><span class="n">event</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">osMessageGet</span><span class="p">(</span><span class="n">msg_q_id</span><span class="p">,</span><span class="w"> </span><span class="n">osWaitForever</span><span class="p">);</span>
<span class="w">        </span><span class="n">ret</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">event</span><span class="p">.</span><span class="n">status</span><span class="p">;</span>
<span class="w">        </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">ret</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">osOK</span><span class="p">)</span>
<span class="w">        </span><span class="p">{</span>
<span class="w">            </span><span class="n">value</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">event</span><span class="p">.</span><span class="n">value</span><span class="p">.</span><span class="n">v</span><span class="p">;</span>
<span class="w">            </span><span class="n">printf</span><span class="p">(</span><span class="s">&quot;receiver: msg incoming[%s]</span><span class="se">\r\n</span><span class="s">&quot;</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="kt">char</span><span class="o">*</span><span class="p">)</span><span class="n">value</span><span class="p">);</span>
<span class="w">        </span><span class="p">}</span>
<span class="w">    </span><span class="p">}</span>
<span class="p">}</span>
<span class="n">osThreadDef</span><span class="p">(</span><span class="n">task_receiver_entry</span><span class="p">,</span><span class="w"> </span><span class="n">osPriorityNormal</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">STK_SIZE_TASK_RECEIVER</span><span class="p">);</span>

<span class="kt">void</span><span class="w"> </span><span class="nf">task_sender_entry</span><span class="p">(</span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">arg</span><span class="p">)</span>
<span class="p">{</span>
<span class="w">    </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">msg_prio_0</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;msg 0&quot;</span><span class="p">;</span>
<span class="w">    </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">msg_prio_1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;msg 1&quot;</span><span class="p">;</span>
<span class="w">    </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">msg_prio_2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;msg 2&quot;</span><span class="p">;</span>

<span class="w">    </span><span class="n">printf</span><span class="p">(</span><span class="s">&quot;sender: post a messgae:[%s]</span><span class="se">\r\n</span><span class="s">&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">msg_prio_2</span><span class="p">);</span>
<span class="w">    </span><span class="n">osMessagePut</span><span class="p">(</span><span class="n">msg_q_id</span><span class="p">,(</span><span class="kt">uint32_t</span><span class="p">)</span><span class="n">msg_prio_2</span><span class="p">,</span><span class="mi">0</span><span class="p">);</span>

<span class="w">    </span><span class="n">printf</span><span class="p">(</span><span class="s">&quot;sender: post a messgae:[%s]</span><span class="se">\r\n</span><span class="s">&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">msg_prio_1</span><span class="p">);</span>
<span class="w">    </span><span class="n">osMessagePut</span><span class="p">(</span><span class="n">msg_q_id</span><span class="p">,(</span><span class="kt">uint32_t</span><span class="p">)</span><span class="n">msg_prio_1</span><span class="p">,</span><span class="mi">0</span><span class="p">);</span>

<span class="w">    </span><span class="n">printf</span><span class="p">(</span><span class="s">&quot;sender: post a messgae:[%s]</span><span class="se">\r\n</span><span class="s">&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">msg_prio_0</span><span class="p">);</span>
<span class="w">    </span><span class="n">osMessagePut</span><span class="p">(</span><span class="n">msg_q_id</span><span class="p">,(</span><span class="kt">uint32_t</span><span class="p">)</span><span class="n">msg_prio_0</span><span class="p">,</span><span class="mi">0</span><span class="p">);</span>

<span class="p">}</span>
<span class="n">osThreadDef</span><span class="p">(</span><span class="n">task_sender_entry</span><span class="p">,</span><span class="w"> </span><span class="n">osPriorityNormal</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">STK_SIZE_TASK_SENDER</span><span class="p">);</span>

<span class="kt">void</span><span class="w"> </span><span class="nf">application_entry</span><span class="p">(</span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">arg</span><span class="p">)</span>
<span class="p">{</span>
<span class="w">    </span><span class="n">msg_q_id</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">osMessageCreate</span><span class="p">(</span><span class="n">osMessageQ</span><span class="p">(</span><span class="n">msg_q</span><span class="p">),</span><span class="nb">NULL</span><span class="p">);</span>

<span class="w">    </span><span class="n">osThreadCreate</span><span class="p">(</span><span class="n">osThread</span><span class="p">(</span><span class="n">task_receiver_entry</span><span class="p">),</span><span class="w"> </span><span class="nb">NULL</span><span class="p">);</span>
<span class="w">    </span><span class="n">osThreadCreate</span><span class="p">(</span><span class="n">osThread</span><span class="p">(</span><span class="n">task_sender_entry</span><span class="p">),</span><span class="w"> </span><span class="nb">NULL</span><span class="p">);</span>

<span class="w">    </span><span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div>
<p>运行结果为：</p>
<div class="highlight"><pre><span></span><code><span class="nl">sender</span><span class="p">:</span><span class="w"> </span><span class="n">post</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="n">messgae</span><span class="o">:</span><span class="p">[</span><span class="n">msg</span><span class="w"> </span><span class="mi">2</span><span class="p">]</span>
<span class="nl">sender</span><span class="p">:</span><span class="w"> </span><span class="n">post</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="n">messgae</span><span class="o">:</span><span class="p">[</span><span class="n">msg</span><span class="w"> </span><span class="mi">1</span><span class="p">]</span>
<span class="nl">sender</span><span class="p">:</span><span class="w"> </span><span class="n">post</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="n">messgae</span><span class="o">:</span><span class="p">[</span><span class="n">msg</span><span class="w"> </span><span class="mi">0</span><span class="p">]</span>
<span class="nl">receiver</span><span class="p">:</span><span class="w"> </span><span class="n">msg</span><span class="w"> </span><span class="n">incoming</span><span class="p">[</span><span class="n">msg</span><span class="w"> </span><span class="mi">2</span><span class="p">]</span>
<span class="nl">receiver</span><span class="p">:</span><span class="w"> </span><span class="n">msg</span><span class="w"> </span><span class="n">incoming</span><span class="p">[</span><span class="n">msg</span><span class="w"> </span><span class="mi">1</span><span class="p">]</span>
<span class="nl">receiver</span><span class="p">:</span><span class="w"> </span><span class="n">msg</span><span class="w"> </span><span class="n">incoming</span><span class="p">[</span><span class="n">msg</span><span class="w"> </span><span class="mi">0</span><span class="p">]</span>
</code></pre></div>





                
              </article>
            </div>
          
          
        </div>
        
          <button type="button" class="md-top md-icon" data-md-component="top" hidden>
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8v12Z"/></svg>
            回到页面顶部
          </button>
        
      </main>
      
        <footer class="md-footer">
  
  <div class="md-footer-meta md-typeset">
    <div class="md-footer-meta__inner md-grid">
      <div class="md-copyright">
  
    <div class="md-copyright__highlight">
      Copyright &copy; 2023 TobudOS
    </div>
  
  
    Made with
    <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
      Material for MkDocs
    </a>
  
</div>
      
    </div>
  </div>
</footer>
      
    </div>
    <div class="md-dialog" data-md-component="dialog">
      <div class="md-dialog__inner md-typeset"></div>
    </div>
    
    <script id="__config" type="application/json">{"base": "../..", "features": ["content.action.edit", "content.action.view", "content.code.annotate", "content.tooltips", "navigation.indexes", "navigation.sections", "navigation.tabs", "navigation.top", "navigation.tracking", "search.highlight", "search.share", "search.suggest", "toc.follow"], "search": "../../assets/javascripts/workers/search.74e28a9f.min.js", "translations": {"clipboard.copied": "\u5df2\u590d\u5236", "clipboard.copy": "\u590d\u5236", "search.result.more.one": "\u5728\u8be5\u9875\u4e0a\u8fd8\u6709 1 \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.more.other": "\u5728\u8be5\u9875\u4e0a\u8fd8\u6709 # \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.none": "\u6ca1\u6709\u627e\u5230\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.one": "\u627e\u5230 1 \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.other": "# \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.placeholder": "\u952e\u5165\u4ee5\u5f00\u59cb\u641c\u7d22", "search.result.term.missing": "\u7f3a\u5c11", "select.version": "\u9009\u62e9\u5f53\u524d\u7248\u672c"}}</script>
    
    
      <script src="../../assets/javascripts/bundle.220ee61c.min.js"></script>
      
    
  </body>
</html>